/*
    Copyright (C) 2011 Rodrigo Castaño - Hugo Arregui, FuDePAN

    This file is part of the Prot-Filer Library

    Prot-Filer is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Prot-Filer is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Prot-Filer.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef INTERNAL_READER_FACTORY
#error Internal header file, DO NOT include this.
#endif

#include <string>

namespace prot_filer
{

template <class F>
class ReaderFactoryMixin
{
public:
    static F* get_instance()
    {
        if (instance == NULL)
        {
            instance = new F();
        }
        return instance;
    }
    static void destroy_instance()
    {
        delete instance;
        instance = NULL;
    }
private:
    static F* instance;
};

template <class F> F* ReaderFactoryMixin<F>::instance = NULL;

template<class F, class E>
class CompressedReaderFactoryMixin : public ReaderFactoryMixin<F>
{
public:
    E* create(const std::string& s) const
    {
        if (s == "compressed")
        {
            return new CompressedReader();
        }
        else
        {
            throw "bad format";
        }
    }
};
}
